﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using PK3Model;

namespace OneLine
{
    class Enemy
    {
        public Enemy(CPK3Model model)
        {
            this.Model = model;
            Random rand = new Random();
            this.Inteligence = (float)(rand.NextDouble() * 0.005);
            //this.Inteligence = 0.0f;
            this.CurrentHealth = 100;
        }

        public CPK3Model Model { get; protected set; }

        public Vector3 Position { get; set; }

        public Vector3 Target { get; set; }

        public Matrix Rotation { get; set; }

        public float Inteligence { get; set; }

        public bool IsDead { get; protected set; }

        public int CurrentHealth { get; set; }

        private Point mapPosition = new Point(0, 0);
        public Point MapPosition
        {
            get
            {
                mapPosition.X = (int)Position.X;
                mapPosition.Y = (int)Position.Z;
                return mapPosition;
            }
        }
        float speed = 0.01f;

        public void Update(GameTime gameTime)
        {
            if (CurrentHealth < 1)
                IsDead = true;

            if (IsDead)
                return;

            Vector3 forward = Target - Position;
            forward.Y = 0;
            forward.Normalize();

            Vector3 newPos = Position + (forward * speed);
            newPos.Z = -newPos.Z;
            Rotation = Matrix.Lerp(Rotation, Matrix.CreateLookAt(Position, newPos, Vector3.Up), 0.25f);
            newPos.Z = -newPos.Z;
             
            Position = newPos;

            //Model.update(gameTime);
        }
    }
}
